//
//  ZBPermission.m
//  ZBUitilty
//
//  Created by xzb on 2018/6/24.
//

#import "ZBPermission.h"
#import <Photos/Photos.h>

@implementation ZBPermission

+ (void)judgePhotoPermission:(void(^)(BOOL allow))complete
{
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
                [UIAlertView bk_showAlertViewWithTitle:@"未获得相册访问权限" message:@"请在iPhone的“设置-隐私-照片”选项中，允许贝店访问你的手机相册" cancelButtonTitle:@"取消" otherButtonTitles:@[@"去设置"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                    if (buttonIndex == alertView.cancelButtonIndex) {
                        return;
                    }
                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                }];
                if (complete)complete(NO);
            } else {
                if (complete)complete(YES);
            }
        });
    }];
}

@end
